package com.example.li.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import com.example.li.fllowstep.R;

@Deprecated
public class PathView extends View {
    private Paint paint;
    private Path path;
    private float x1, y1;
    private float x2, y2;

    public PathView(Context context) {
        super(context);
//        init();
    }

    public PathView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
//        init();
    }

    public PathView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
//        init();
    }

    private void init() {
        // 创建画笔
        paint = new Paint();
        paint.setColor(getResources().getColor(R.color.colorPrimary));  // 设置颜色
        paint.setStrokeWidth(1);   // 设置宽度
        paint.setAntiAlias(true);   // 抗锯齿
        paint.setStyle(Paint.Style.STROKE);
        path = new Path();
        x1 = ((ViewGroup) getParent()).getWidth() / 2;
        y1 = ((ViewGroup) getParent()).getHeight() / 2;
        x2 = ((ViewGroup) getParent()).getWidth();
        y2 = ((ViewGroup) getParent()).getHeight();
        Log.d("init", x1 + "\n" + y1);
        Log.d("init", x2 + "\n" + y2);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        init();

        path.moveTo(x1, y1);

        //贝塞尔曲线
        float quaX = x1 / 4;
        float quaY = (y1 + y2) / 2;
        if (y2 - y1 < 0) {
            quaX = (x1 + x2) / 2;
            quaY = y2 - 100;
        } else if (y2 - y1 < 50) {
            quaX = (x1 + x2) / 2;
            quaY = y1 - 50;
        }
        path.quadTo(quaX, quaY, x2, y2);
        canvas.drawPath(path, paint);
    }


}
